//
//  ViewController.m
//  alipaydemo
//
//  Created by 李鹏飞 on 2020/4/23.
//  Copyright © 2020 李鹏飞. All rights reserved.
//

#import "ViewController.h"
#import <AlipaySDK/AlipaySDK.h>
#import "Masonry.h"
#import "Helper.h"

#import "WXApi.h"
#import "WXApiObject.h"

#define SIGN_KEY @"58530c0324c5fee027680c740a6f0971"
#define SIGN_KEY @"58530c0324c5fee027680c740a6f0971"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *btn = [UIButton new];
    btn.backgroundColor = [UIColor systemBlueColor];
    [btn setTitle:@"支付宝支付" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(handleAlipay) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.view).with.offset(20);
        make.top.equalTo(self.view).with.offset(100);
        make.trailing.equalTo(self.view).with.offset(-20);
        make.height.mas_equalTo(44);
    }];
    
    UIButton *btnWechat = [UIButton new];
       btnWechat.backgroundColor = [UIColor systemGreenColor];
       [btnWechat setTitle:@"微信支付" forState:UIControlStateNormal];
       [btnWechat addTarget:self action:@selector(handleWechatPay) forControlEvents:UIControlEventTouchUpInside];
       [self.view addSubview:btnWechat];
       [btnWechat mas_makeConstraints:^(MASConstraintMaker *make) {
           make.leading.equalTo(self.view).with.offset(20);
           make.top.equalTo(btn.mas_bottom).with.offset(100);
           make.trailing.equalTo(self.view).with.offset(-20);
           make.height.mas_equalTo(44);
       }];
}
- (void)handleAlipay{

//    NSString *str = @"app_id=2021001110653311&format=JSON&charset=utf-8&sign_type=RSA2&version=1.0&return_url=http%3A%2F%2Fjijian-api-dev.japm.top&notify_url=http%3A%2F%2Fjijian-api-dev.japm.top%2Fnotify%2Falipay&timestamp=2020-04-26+09%3A47%3A32&biz_content=%7B%22total_amount%22%3A0.01%2C%22subject%22%3A%22%5Cu6781%5Cu4ef6%22%2C%22body%22%3A%229223372036854775807+v1%22%2C%22timeout_express%22%3A1587866252%2C%22out_trade_no%22%3A%229223372036854775807%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&method=alipay.trade.app.pay&sign=IptB1sbsnbVNk9PJoozd3W%2BkW%2BM7PkzTD%2FkhNvTBnWVauoBiUbRseo3IRvY2bNgX%2FFgqWmL%2BzPrzTEcNRbtLaSWmymVgXlD2EDJxIEXzEtpW9oZw1XOP3DZFWxoPtpTQtgmqKxbTrkmY8AFo6AHDyHEVhD6jT4mLEZcl5X5dIe5zX2Y3uqiPH6Q7l5z7yAaODw8CPSQgmFpopYQw32HCQ%2BP8FTUBi1d1dguE%2BfN6BM6ztns6uMUbc2xmWEvDSM75uETuR59d04s70TRHWlLxTddcM%2BJgMPaGa9yCi7LnQy9JQMBVI7qUg6wluYrwwI09cNKIy%2BwzVk73S0HA4eaUeQ%3D%3D";
//    [[AlipaySDK defaultService] payOrder:str fromScheme:@"com.jijian.app" callback:^(NSDictionary *resultDic) {
//        
//    }];
    NSDictionary *dic = @{
                          @"pay_type":@"1",
                          @"order_no":@"20200422104116806438",
                          };
    NSString *url;
    url = [NSString stringWithFormat:@"http://img.shangzh.com/v1/pay"];

    [Helper post:url parameters:dic success:^(id responseObject) {
        NSLog(@"%@",responseObject);
        NSString *payOrder = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"data"]];
           NSLog(@"::%@",payOrder);
        [[AlipaySDK defaultService] payOrder:payOrder fromScheme:@"com.jijian.app" callback:^(NSDictionary *resultDic) {

        }];

    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
    
}
- (void)handleWechatPay{
    
    PayReq *req = [[PayReq alloc] init];
    req.openID = @"wx15d9a60872e47468";
    req.partnerId = @"1499702682";
    req.prepayId = @"wx24211911601476d470f876421247150900";
    req.package = @"Sign=WXPay";
    req.nonceStr = @"5ea2e74fa15a0";
    req.timeStamp = 1587734351;//@"timestamp";
    req.sign = @"364919143C70DA41727701F3DE3B277A";
    
    
//    req.openID = dicData[@"appid"];
//       req.partnerId = dicData[@"partnerid"];
//       req.prepayId = dicData[@"prepayid"];
//       req.package = dicData[@"package"];
//       req.nonceStr = dicData[@"noncestr"];
//       req.timeStamp = [dicData[@"timestamp"] intValue];
//       req.sign = dicData[@"sign"];
    
    [WXApi sendReq:req completion:^(BOOL success) {
        
    }];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleWXPaySuccess) name:@"paySuccess" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleWXPaySFail) name:@"payFail" object:nil];
}
- (void)handleWXPaySuccess
{
    NSLog(@"微信支付成功");
}
- (void)handleWXPaySFail
{
    NSLog(@"微信支付失败");
}

- (void)handleAlipay_success{
    NSLog(@"支付宝支付success");
}

- (void)handleAlipay_faild{
    NSLog(@"支付宝支付faild");
}


@end


/*
 app_id=2015052600090779&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22seller_id%22%3A%22%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%221%22%2C%22body%22%3A%22%E6%88%91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22%2C%22out_trade_no%22%3A%22IQJZSRC1YMQB5HU%22%7D&charset=utf-8&format=json&method=alipay.trade.app.pay&notify_url=http%3A%2F%2Fdomain.merchant.com%2Fpayment_notify&sign_type=RSA2&timestamp=2016-08-25%2020%3A26%3A31&version=1.0&sign=cYmuUnKi5QdBsoZEAbMXVMmRWjsuUj%2By48A2DvWAVVBuYkiBj13CFDHu2vZQvmOfkjE0YqCUQE04kqm9Xg3tIX8tPeIGIFtsIyp%2FM45w1ZsDOiduBbduGfRo1XRsvAyVAv2hCrBLLrDI5Vi7uZZ77Lo5J0PpUUWwyQGt0M4cj8g%3D
 */

/*
app_id=2021001155685008&format=JSON&charset=utf-8&sign_type=RSA2&version=1.0&notify_url=http%3A%2F%2Fjijian-api-dev.japm.top%2Fnotify%2Falipay&timestamp=2020-04-24+16%3A26%3A44&biz_content=%7B%22out_trade_no%22%3A9223372036854775807%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%22%22%2C%22passback_params%22%3A%22pay_type%253D1%2526module%253Dv1%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&method=alipay.trade.app.pay&sign=bA6kqEnkVqbVotZDeHRIf%2FRHJbQb8AciNRtebUzatpRNo2bbuKisFHDaML%2BxapFlxQ1yomeudANJwx0ngiZq9Le3XH5U6Wh0b0tY54xAVGbD%2FMkoDh5CdO8fwMfDsRpRVPYGsRsfze910Gue%2Fkhdv7fN2yQrbCNykNN5x9bWrnby05Gb9P5gtIK1XqeXeLsFHCmvOu6ailpSqMydvy8WHlBhhaIh1bQlpD1bjfwbMxRgk521VA0j9pgumlvUhgFKcgtLhSAYaNXRhBc7I61CRRm%2FCFkwJNtBzA4iKBBh9jyaGVnzsYPc8BNLz%2FMrxVmVr7rb2O6PZrT7KvD0TyY%2Bzw%3D%3D
 */
